<template>
  <div class="tab_container">
    <transition name="fade">
      <vue-markdown class="md_container"
                    v-if="mdContent">{{mdContent}}</vue-markdown>
    </transition>
    <transition name="fade">
      <div class="tab_container_empty"
           v-if="!mdContent">暂无描述</div>
    </transition>
  </div>
</template>

<script>
import path from 'path'
export default {
  name: 'TabDetail',
  props: {
    info: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  components: {
    VueMarkdown: () => import('vue-markdown')
  },
  data () {
    return {
      mdUrl: '',
      mdContent: ''
    }
  },
  created () {

  },
  watch: {
    info: {
      deep: true,
      immediate: true,
      handler (val) {
        this.initInfo()
      }
    }
  },
  methods: {
    initInfo () {
      this.mdUrl = ''
      this.mdContent = ''
      if (this.info.local) {
        this.mdUrl = path.resolve(this.info.local, '..', 'README.md')
        if (bbtools.fs.existsSync(this.mdUrl)) {
          this.mdContent = bbtools.fs.readFileSync(this.mdUrl).toString()
        }
      }
    }
  }
}
</script>

<style lang="less" scoped>
@import url("../../../themes/index.less");
.tab_container {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 15px;
  box-sizing: border-box;
  overflow-y: auto;
  .md_container {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 15px;
    top: 15px;
  }
  &_empty {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    font-size: 12px;
    color: @darkTextColor4;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
  }
}
</style>